package com.example.tacocloudapi;

import com.example.tacoclouddomain.Ingredient;
import com.example.tacoclouddomain.Taco;
import lombok.Getter;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.server.core.Relation;

import java.util.Date;

@Relation(value = "taco", collectionRelation = "tacos")//json:taco, TacoResource objects:tacos
public class TacoResource extends RepresentationModel<TacoResource> {
    @Getter
    private final String name;
    @Getter
    private final Date createdAt;
    @Getter
    private final CollectionModel<IngredientResource> ingredients;

    private static final IngredientResourceAssembler ingredientAssembler = new IngredientResourceAssembler(
            IngredientController.class, IngredientResource.class
    );

    public TacoResource(Taco taco) {
        this.name = taco.getName();
        this.createdAt = taco.getCreatedAt();
        this.ingredients = ingredientAssembler.toCollectionModel(taco.getIngredients());
    }
}
